package cn.dogger.easyboot.system.service.impl;


import cn.dogger.easyboot.common.exception.RollBackException;
import cn.dogger.easyboot.system.domain.bo.SysNoticeBO;
import cn.dogger.easyboot.system.domain.dto.SysNoticeDTO;
import cn.dogger.easyboot.system.domain.entity.SysNotice;
import cn.dogger.easyboot.system.domain.vo.SysNoticeDetail;
import cn.dogger.easyboot.system.domain.vo.SysNoticeVO;
import cn.dogger.easyboot.system.mapper.SysNoticeMapper;
import cn.dogger.easyboot.system.service.SysNoticeService;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
* 通知公告表
* @author dogger
* 2022-04-16
*/
@Service
public class SysNoticeServiceImpl  extends ServiceImpl<SysNoticeMapper, SysNotice> implements SysNoticeService {

         private final SysNoticeMapper mapper;

         public SysNoticeServiceImpl(SysNoticeMapper mapper) {
            this.mapper = mapper;
         }
         
    @Override
    public List<SysNoticeVO> page(SysNoticeDTO dto) {
       // dto.setCreatedBy(TokenUtil.getLoginInfo().getUserId());
        List<SysNoticeVO> list = mapper.list(dto);
        return list;
    }


    @Override
    @Transactional(rollbackFor = RollBackException.class)
    public void add(SysNoticeBO bo) {
        SysNotice entity = BeanUtil.copyProperties(bo, SysNotice.class);
        mapper.insert(entity);
    }

    @Override
    @Transactional(rollbackFor = RollBackException.class)
    public void edit(SysNoticeBO bo) {
        SysNotice entity = BeanUtil.copyProperties(bo, SysNotice.class);
        mapper.updateById(entity);
    }

    @Override
    public SysNoticeDetail detailById(String id) {
       SysNotice entity =  mapper.selectById(id);
        return BeanUtil.toBean(entity,SysNoticeDetail.class);
    }

    @Override
    public void removeByIds(String[] ids) {
        List<String> list = Arrays.asList(ids);
        mapper.deleteBatchIds(list);
    }
}